package com.util.common.sql;

public class OracleBlockImp extends AbstractCommSQLBlock implements OracleBlock {
	
	@Override
	public String dateFormate(String dateField, String formate){
		return "to_char("+dateField+","+formate+")";
	}
	@Override
	public String dateParse(String dateValue, String formate){
		return " to_date('"+dateValue+"','"+formate+"') ";
	}
	
	/**
	 * 获得指定条数的sql语句
	 * @param sql
	 * @param between
	 * @return
	 */
	public String mergePageSQL(String sql,String startLine,String pageSize){
		String sqlStr = "";
		sqlStr = "select results.* from ("
			+"select t2.*,rownum rownumber from (";
		sqlStr += sql;
		sqlStr += " )t2"
			+")results WHERE results.rownumber between "+startLine+" and "+pageSize;

		return sqlStr;
	}
	@Override
	public String mergeBetween(String sql, String between, String orderByColumn) {
		orderByColumn = ( orderByColumn != null && !"".equals(orderByColumn.trim()) ) ?
				" ORDER BY " + orderByColumn : "";
		String sqlStr = "select results.* from ("
			+ "select t2.*,rownum rownumber from ("
			+ sql + orderByColumn + ")t2"
			+ ")results WHERE results.rownumber between "+between+orderByColumn;

		return sqlStr;
	}

}